import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false, //登录状态
		userInfo: "", // 缓存用户信息
		token:"",     // token
		userID:"", //微信登录 唯一标识
		userType:"pm",
		wkID:"",
		pm_company:"" //公司ID
	},
	mutations: {
		// 普通用户登录退出
		signing(state, data) {
			state.hasLogin = true;
			state.userInfo = data.userInfo;
			state.token = data.token;
			state.userID = data.userID;
			state.userType = data.userType;
			state.wkID = data.wkID
			state.pm_company = data.pm_company
			uni.setStorageSync("token",data.token) 
			uni.setStorageSync("userInfo",data.userInfo) //
			uni.setStorageSync("userID",data.userID)
			uni.setStorageSync("userType",data.userType)
			uni.setStorageSync("wkID",data.wkID)
			uni.setStorageSync("pm_company",data.pm_company)
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = "";
			state.token = "";
			state.userID = "";
			state.userType = "wk";
			state.wkID = "";
			state.pm_company = ""
			try{
				uni.removeStorageSync('token');
				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('userID');
				uni.removeStorageSync('userType');
				uni.removeStorageSync('wkID');
				uni.removeStorageSync('pm_company');
			}catch(e){}
		}
	},
	actions: {
	
	}
})

export default store
